package com.yq.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/07/04 20:23
 */
public class LoginServer {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ServerSocket serverSocket = new ServerSocket(8888);

        // 获取连接
        Socket socket = serverSocket.accept();
        // 接收数据
        InputStream inputStream = socket.getInputStream();
        ObjectInputStream in = new ObjectInputStream(inputStream);
        User o = (User) in.readObject();
        System.out.println("接收的用户信息为："+o);

        String result;
        if ("admin".equals(o.username) && "admin".equals(o.password)){
            System.out.println("用户名 密码正确");
            result = "用户名 密码正确";
        }else {
            System.out.println("用户密码不正确");
            result ="不正确";
        }
        //向client端发送登录的结果
        OutputStream out = socket.getOutputStream();
        out.write(result.getBytes());

        socket.close();
        serverSocket.close();
    }
}
